#include "Model.h"

Model::Model(void)
{
}
Model::~Model(void)
{
}

void Model::Initialize(HWND WindowHandle, HINSTANCE hInstance, ID3D11Device* Device, ID3D11DeviceContext* DeviceContext)
{
	D3DDevice = Device;
	D3DDeviceContext = DeviceContext;
}
void Model::Update(int DeltaTime)
{

}
void Model::Shutdown()
{
	unsigned int i = 0;
	do
	{
		EffectPosition3NormalColor* temp = static_cast<EffectPosition3NormalColor*>(Effects[i]);
		temp->Shutdown();
		i = i + 1;
	}
	while (i != Effects.size());
	Effects.clear();
}
void Model::Render()
{
		unsigned int i = 0;
		do 
		{
			//Effects[i].Render();
			EffectPosition3NormalColor* temp = static_cast<EffectPosition3NormalColor*>(Effects[i]);
			temp->Render();
			ConstantBufferStruct cb;
			cb.mWorld = XMMatrixTranspose( ViewCamera->GetWorldMatrix() );
			cb.mView = XMMatrixTranspose( ViewCamera->GetViewMatrix() );
			cb.mProjection = XMMatrixTranspose( ViewCamera->GetProjectionMatrix() );
			D3DDeviceContext->UpdateSubresource(temp->GetConstantBuffer(), 0, nullptr, &cb, 0, 0 );
			i = i + 1;
		}
		while ( i != Effects.size() );
}

void Model::SetCamera(Camera* cam)
{
	ViewCamera = cam;
}

void Model::NumberOfEffects(int NumberOfEffects)
{
	Effects.resize(NumberOfEffects);

	unsigned int i = 0;
	do
	{
		Effects[i]= new EffectPosition3NormalColor;
		EffectPosition3NormalColor* temp = static_cast<EffectPosition3NormalColor*>(Effects[i]);
		temp->Initialize(0,0,D3DDevice, D3DDeviceContext);
		i = i + 1;
	}
	while (i != Effects.size());
}

void Model::AddVertex(Position3NormalColor Vertex, int MaterialIndex)
{
	EffectPosition3NormalColor* temp = static_cast<EffectPosition3NormalColor*>(Effects[MaterialIndex]);
	temp->AddVertex(Vertex);
}

void Model::Create()
{
	unsigned int i = 0;
	do
	{
		EffectPosition3NormalColor* temp = static_cast<EffectPosition3NormalColor*>(Effects[i]);
		temp->Create();
		i = i + 1;
	}
	while (i != Effects.size());
}
